from selenium.common.exceptions import TimeoutException
import time
import random
from selenium import webdriver
import selenium
from collections import OrderedDict
import platform

import bpython
import inspect


Driver_path = './chromedriver.exe'
if platform.system() == 'Linux':
    Driver_path = './chromedriver'

# ai_kw = ['人工智能','机器学习','深度学习','强化学习','智能机器人','聊天机器人','虚拟助理','计算机视觉','图像识别','人脸识别','文字识别','可视化搜索','指纹识别','虹膜识别','手势控制','自然语言理解','自然语言处理','文本分析','语音识别','语义网络','语义搜索','无人车','无人驾驶','自动驾驶','辅助驾驶','自动泊车','智能投顾','神经计算','神经网络','算法博弈论','知识工程','知识表示','知识图','逻辑编程','规则基系统','规则引擎','进化计算','认知计算','计算智能','超级智能','自动推理','模糊逻辑','智能代理','感知计算','Artificial intelligence','Machine learning','Deep learning','Reinforcement learning','Robots','Chatterbot','Virtual Assistant','Computer Vision','Image Recognition','Facial Recognition','text recognition','Visual Search','fingerprint recognition','Iris recognition','Gesture control','Natural language understanding','Natural language processing','Text Analytics','Voice Recognition','Semantic Web','Semantic Search','Autonomous vehicle','autopilot','self driving','ADAS','Automatic parking','robo-adviser','Neurocomputing','Neural network','计算博弈论','基于规则系统','感知计算','智能主体','知觉计算','Robotics','chat bot','face recognition','finger print recognition','NLP','TEXT ANALYSIS','Autonomous car','auto pilot','self-driving','Advanced driver assistance system','robo-advisor','Neurocomput','基于规则的系统','智能体','Robotic','Autonomous cars','auto-pilot','self drive','Advanced driver assistance system','robo adviser','Algorithmic game theory','Knowledge engineering','Knowledge representation','Knowledge graph','Logic programming','Rule-based system','Rule engine','Evolutionary computation','Cognitive computing','Computational intelligence','Superintelligence','Automated reasoning','Fuzzy logic','Intelligent agent','Perceptual computing','Autonomous vehicles','self-drive','driver assistance systems','robo advisor','Algorithmic game theor','Rule based system','Perceptual comput','driver assistance system',]
ai_kw = ['感知计算','Artificial intelligence','Machine learning','Deep learning','Reinforcement learning','Robots','Chatterbot','Virtual Assistant','Computer Vision','Image Recognition','Facial Recognition','text recognition','Visual Search','fingerprint recognition','Iris recognition','Gesture control','Natural language understanding','Natural language processing','Text Analytics','Voice Recognition','Semantic Web','Semantic Search','Autonomous vehicle','autopilot','self driving','ADAS','Automatic parking','robo-adviser','Neurocomputing','Neural network','计算博弈论','基于规则系统','感知计算','智能主体','知觉计算','Robotics','chat bot','face recognition','finger print recognition','NLP','TEXT ANALYSIS','Autonomous car','auto pilot','self-driving','Advanced driver assistance system','robo-advisor','Neurocomput','基于规则的系统','智能体','Robotic','Autonomous cars','auto-pilot','self drive','Advanced driver assistance system','robo adviser','Algorithmic game theory','Knowledge engineering','Knowledge representation','Knowledge graph','Logic programming','Rule-based system','Rule engine','Evolutionary computation','Cognitive computing','Computational intelligence','Superintelligence','Automated reasoning','Fuzzy logic','Intelligent agent','Perceptual computing','Autonomous vehicles','self-drive','driver assistance systems','robo advisor','Algorithmic game theor','Rule based system','Perceptual comput','driver assistance system',]
# setInterval("jQuery('.next').click()",5000); 
cookies = 'JSESSIONID="ajax:7752026804203399614"; bcookie="v=2&4650b692-18ed-4049-8bdb-9c1c4fffc35f"; bscookie="v=1&201707250439409deb0aea-3b97-43a2-838b-1d4feb27909eAQH_C8Aa0xpyZc5l70zk5nNwLEwAd3fH"; lidc="b=VGST08:g=394:u=1:i=1501052095:t=1501138495:s=AQE_v1uo8AKGgSO_x34FVus1emzma-wZ"; visit="v=1&M"; _lipt=CwEAAAFdgq3iz_Qz2V_iL8JXlvNz97W3k-gJeGV17Lu0evCeAkstol_xteWiRNe85q9hqWmv6rmaxP8w88zyGedF-KEsKQPPN3xTfvBq96D9Y5FpSdhV_KLwPp9v3b4K; _ga=GA1.2.1444402639.1501032016; lang="v=2&lang=en-us"; liap=true; sl="v=1&n1M0h"; li_at=AQEDASNGaHQFRfV3AAABXX2tSoMAAAFdgsyx7k0Ac2XeBellauh8RxF-g3hpv5SFKMLa__G4sdafgpZu24XIEYf_PhpHVYcTUaJNS3kdLYW8Gq8QhAzru86H-nfK-rZW3rpk9zju351XBr8tm6fwyCvY'


def parse_cookie(cookies):
    cookielist = cookies.split("; ")
    cookies = []
    cookies = []
    for sel in cookielist:
        cookie = {}
        Sel = sel.split("=")
        if len(Sel) == 2:
            cookie['name'] = Sel[0]
            cookie['value'] = Sel[1]
            cookie['domain'] = '.linkedin.com'
        if len(Sel) > 2:
            cookie['name'] = Sel[0]
            cookie['value'] = '='.join(Sel[1:])
            cookie['domain'] = '.linkedin.com'
        cookies.append(cookie)
    return cookies

COOKIES = parse_cookie(cookies)

# def main():

chromeOptions = webdriver.ChromeOptions()
chromeOptions.add_argument('proxy-server=http://localhost:8080')
chromeOptions.add_argument('ignore-certificate-errors')
chromeOptions.add_argument('test-type')
chromeOptions.add_argument('disable-images')
# chromeOptions.add_argument('user-data-dir=./chrome')
chromeOptions.add_argument('disable-gpu') 
# chromeOptions.add_argument('headless')
# chromeOptions.add_argument('user-agent=Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.109 Safari/537.36')



 

browser=webdriver.Chrome(executable_path=Driver_path,chrome_options=chromeOptions)

browser.set_page_load_timeout(300)

# 刷新页面
# browser.refresh()

browser.get('https://www.linkedin.com/')
time.sleep(5)
print('cookie')
for ck in COOKIES:
    browser.add_cookie(ck)
time.sleep(2)


browser.get('https://www.linkedin.com/jobs/search/?f_L=de%3A0%2Cgb%3A0&keywords=Machine learning&location=Worldwide&locationId=OTHERS.worldwide')

local = inspect.currentframe().f_locals
bpython.embed(local)

for _ in range(90):
    

    browser.execute_script("$(window).scrollTop(9000)")
    time.sleep(1)
    browser.execute_script("$('.next').click()")
    time.sleep(2)
    print('click')
      
print('over')
time.sleep(3000)


# if __name__ == '__main__':

#     try:
#         main()
#     except selenium.common.exceptions.WebDriverException as e:
#         print(e)